//
//  FeedbackViewController.m
//  jungoo
//
//  Created by Dang Quang Trung on 7/25/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "FeedbackViewController.h"
#import "FeedbackAddViewController.h"
@implementation FeedbackViewController

@synthesize tableView = _tableView;
@synthesize myCell;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

-(void)initNavigationBar 
{
    self.navigationController.navigationBar.hidden = NO;
    
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    
    UIView *overlayView = [[UIView alloc] initWithFrame:CGRectMake(0, 43, 320, 1)];
    [overlayView setBackgroundColor:[UIColor whiteColor]];
    [self.navigationController.navigationBar addSubview:overlayView]; // navBar is your UINavigationBar instance
    [overlayView release];
    
    UIButton *BtnBack = [UIButton buttonWithType:UIButtonTypeCustom];
    BtnBack.frame = CGRectMake(0, 0, 29, 29);
    [BtnBack setImage:[UIImage imageNamed:@"back-button.png"] forState:UIControlStateNormal];
    [BtnBack addTarget:self action:@selector(backPressed) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc]initWithCustomView:BtnBack];
    //[BtnBack release];
    self.navigationItem.leftBarButtonItem =backItem;
    [backItem release];
    
    [self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"home_bg.png"]]]; 
}
- (void)applyTitle:(NSString*)title
{       
    UILabel * label = [[[UILabel alloc] initWithFrame:CGRectMake(0,0,320,43)] autorelease];
	label.textColor = [UIColor blackColor];
	label.backgroundColor = [UIColor clearColor]; 
	label.text = title;
    label.textColor = [UIColor colorWithRed:0.573 green:0.573 blue:0.573 alpha:1];
	self.navigationItem.titleView = label;
	[label sizeToFit];    
}
-(void) backPressed 
{
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)viewDidLoad
{    
    [super viewDidLoad];
       
    self.tableView.backgroundColor = [UIColor clearColor];
    self.tableView.opaque = NO;
    self.tableView.backgroundView = nil;
    
}

-(void)viewWillAppear:(BOOL)animated
{
    [self initNavigationBar];    
    [self applyTitle:@"Feedback"];
    [super viewWillAppear:animated];
}
- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(void)dealloc
{
    [self setTableView:nil];
    [myCell release];
    [super dealloc];
}

#pragma mark - Table Delegate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;    
}

/*
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{
    return nil;
}
 */
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
            
        static NSString *CellIdentifier = @"FeedbackCell";
        
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell  = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
            [[NSBundle mainBundle] loadNibNamed:@"FeedbackCell" owner:self options:nil];
            cell = myCell;
            self.myCell = nil;
        }
        UIImageView *icon = (UIImageView *)[cell viewWithTag:1];
        
        UILabel *firstText = (UILabel *)[cell viewWithTag:2];
        /*
        / UILabel *secondText = (UILabel *)[cell viewWithTag:3];
        */
        switch (indexPath.row) {
            case 0:
            {
                firstText.text = @"Errors/Bugs";
                icon.image = [UIImage imageNamed:@"bugs-icon.png"];
                break;
            }
            case 1:
            {
                firstText.text = @"Ideas";
                icon.image = [UIImage imageNamed:@"ideas-icon.png"];
                break;                
            }
           
            case 2:
            {
                icon.image = [UIImage imageNamed:@"business-icon.png"];
                firstText.text = @"Business Matters";
                break;
            }
            case 3:
            {
                icon.image = [UIImage imageNamed:@"questions-icon.png"];
                firstText.text = @"Questions";
                break;
            }
            default:
                break;
        }
        firstText.textColor = [UIColor colorWithRed:0. green:0.678 blue:0.941 alpha:1];
        [firstText sizeToFit];
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor whiteColor];
        return cell;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
           switch (indexPath.row) {
            case 0:
            {
                
                FeedbackAddViewController *faVC = [[FeedbackAddViewController alloc] initWithNibName:@"FeedbackAddViewController" 
                                                                                   bundle:nil];
                faVC.type = 0;
                [self.navigationController pushViewController:faVC animated:YES];
                [faVC release];
               
                break;
                 
            }
               case 1:
               {
                   
                   FeedbackAddViewController *faVC = [[FeedbackAddViewController alloc] initWithNibName:@"FeedbackAddViewController" 
                                                                                                 bundle:nil];
                   faVC.type = 1;
                   [self.navigationController pushViewController:faVC animated:YES];
                   [faVC release];
                   
                   break;
                   
               }
               case 2:
               {
                   
                   FeedbackAddViewController *faVC = [[FeedbackAddViewController alloc] initWithNibName:@"FeedbackAddViewController" 
                                                                                                 bundle:nil];
                   faVC.type = 2;
                   [self.navigationController pushViewController:faVC animated:YES];
                   [faVC release];
                   
                   break;
                   
               }
               case 3:
               {
                   
                   FeedbackAddViewController *faVC = [[FeedbackAddViewController alloc] initWithNibName:@"FeedbackAddViewController" 
                                                                                                 bundle:nil];
                   faVC.type = 3;
                   [self.navigationController pushViewController:faVC animated:YES];
                   [faVC release];
                   
                   break;
                   
               }
            
            default:
                break;
        }
    
}

@end
